const request = require('request')
const { baseUrl } = require('./config')
/**
 *
 * loginHanle
 * @param {string} username
 * @param {string} password
 * @param {request.jar} jar
 * @param {function} cb
 * @returns {status: 'success'}
 */
module.exports = (username, password, jar, cb) => {
  request.post({
    url: `${baseUrl}api/login`,
    jar: jar,
    form: {
      username: username,
      password: password
    }
  }, (err, httpResponse, body) => {
    let resp = JSON.parse(body)
    if (resp.status === 'success') {
      return cb({
        status: 'success'
      })
    }
    return cb({
      status: 'failure'
    })
  })
}